-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: Fix invoker to work when using dataclass with from_dict but dataclass… #9434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… is already given
Pull Request Test Coverage Report for Build 15210934031Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
@vblagoje I'd also appreciate your review on this since you worked on ComponentTool in the past |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK but I would like if @vblagoje can review too
@@ -159,15 +159,19 @@ def component_invoker(**kwargs): | |||
target_type = get_args(param_type)[0] if get_origin(param_type) is list else param_type | |||
if hasattr(target_type, "from_dict"): | |||
if isinstance(param_value, list): | |||
param_value = [target_type.from_dict(item) for item in param_value if isinstance(item, dict)] | |||
resolved_param_value = [ | |||
target_type.from_dict(item) if isinstance(item, dict) else item for item in param_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjrl - just one clarification - so the only difference to previous code state is that we now include other items in the list - that are not dicts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we keep other items in the list (or really all items in a list) that aren't dicts. If we don't do this and a user passes this
agent_tool.invoke(messages=[ChatMessage.from_user("Tell me the latest news about gpus")])
we actually run the agent_tool with
messages=[ChatMessage.from_user("Tell me the latest news about gpus")]
# turns into
messages=[]
# then we run Agent Tool with an empty list of messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is relevant in two cases:
- If a user is trying to use a tool manually with
invoke
or within a custom component - If we pass
inputs_from_state
to a Tool which are already fully formed dataclasses. E.g. If I pass themessages
from State into the input of a Tool that accepts ChatMessages. I wouldn't expect the invoke function to then remove all the messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it makes total sense 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find @bilgeyucel
…class… (#9434) * Fix invoker to work when using dataclass with from_dict but dataclass is already given * add reno * Add unit test * Remove line
Related Issues
Proposed Changes:
Fix invoker to work when using dataclass with from_dict but dataclas is already given
Updated the
component_invoker
method to allow fully formed dataclass objects to pass through. Otherwise we silently remove the parameter value.Originally found by @bilgeyucel when creating an tool using Agent + ComponentTool and calling
How did you test it?
Notes for the reviewer
Checklist
fix:
,feat:
,build:
,chore:
,ci:
,docs:
,style:
,refactor:
,perf:
,test:
and added!
in case the PR includes breaking changes.